package leetcode.f1t100;

/**
 * 移除数组重复项
 * https://leetcode.com/problems/remove-duplicates-from-sorted-array/
 *
 * @Author lichongxiao
 * @Date 2022/10/8 11:05
 */
public class Q26_RemoveDuplicatesFromSortedArray {
    public int removeDuplicates1(int[] nums) {
        int curIndex = 0;
        for (int i = 1, length = nums.length; i < length; i++) {
            if (nums[curIndex] < nums[i]) {
                nums[++curIndex] = nums[i];
            }
        }
        return curIndex + 1;
    }

    public int removeDuplicates(int[] nums) {
        int curIndex = 0;
        for (int num : nums) {
            if (nums[curIndex] < num) {
                nums[++curIndex] = num;
            }
        }
        return curIndex + 1;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1,1,3,4};
        int count = new Q26_RemoveDuplicatesFromSortedArray().removeDuplicates(nums);
        for (int i = 0; i < count; i++) {
            System.out.println(nums[i]);
        }
    }
}
